// const test =computed(()=>store.state.test.count)
// mutations
// 	store.commit('test/add', 5)
// actions
// store.dispatch('login/login')
//  使用模块化
import {
	myShowToast
} from "@/uitls/tool.js"
export default {
	// 独立命名空间
	namespaced: true,
	state: {
		addClassMain: uni.getStorageSync("addClassMain") || [{
				title: "支出",
				data: 0
			},
			{
				title: "收入",
				data: 1
			}
		],
		addClassOne: uni.getStorageSync("addClassOne") || {
			0: ["餐饮", "购物", "交通", "日用", "零食", "游戏", "医疗", "捐款", "其他"],
			1: ["工资", "奖金", "投资", "其他"]
		}
	},
	getters: {},
	mutations: {
		updateData(state) {
			if (state.addClassMain != uni.getStorageSync("addClassMain")) {
				uni.setStorageSync('addClassMain', state.addClassMain)
			}
			if (state.addClassOne != uni.getStorageSync("addClassOne")) {
				uni.setStorageSync('addClassOne', state.addClassOne)
			}
		},
		addAddClassOne(state, data) {
			const {
				newTag,
				newClass
			} = data;
			if (state.addClassOne[newTag].indexOf(newClass) == -1) state.addClassOne[newTag].push(newClass)
			else myShowToast("已有相同标签,请勿重复添加")
			this.commit("AddClass/updateData")
		},
		delAddClassOne(state, data) {
			const {
				className,
				classTag
			} = data
			state.addClassOne[classTag].splice(state.addClassOne[classTag].indexOf(className), 1)
			this.commit("AddClass/updateData")
		}
	},
	actions: {}
};